<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 输入要猜数字
      let age = prompt("input age?", 20);
      let x = true;
      while (x) {
        // 反复要求用户输入数字
        x = prompt("age?", 0);
        if (x === null) {
          console.log("结束游戏");
        } else if (x > age) {
          console.log("大了");
        } else if (x < age) {
          console.log("小了");
        } else {
          console.log("猜对了");
        }
      }
    </script>
  </body>
</html>
